package com.gao.activitidemo.deploy;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.junit.Test;

import java.io.*;
import java.util.zip.ZipInputStream;

/**
 * @author gaofeng
 * @date 2022年09月11日 17:20
 */
public class ActivitiDeployByZip {
    /**
     * 使用zip批量部署
     */
    @Test
    public void testDeployProcessByZip() {
        // 1.创建ProcessEngine
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        // 2.创建TaskService
        RepositoryService repositoryService = processEngine.getRepositoryService();
        // 3.流程部署
        /*
        * 读取资源文件,构造InputStream
        *  注: 如果该资源在resources目录下,需要把resources目录设置成Sources Root,不然没权限读取,获取的流对象为null
        */
        InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("bpmn/evection.zip") ;
        System.out.println(ActivitiDeployByZip.class.getClassLoader());
        assert inputStream != null;
        ZipInputStream zipInputStream = new ZipInputStream(inputStream) ;
        Deployment deploy = repositoryService.createDeployment().addZipInputStream(zipInputStream).deploy();
        System.out.println("流程id:" + deploy.getId());
    }
}
